home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_ciel_client_search.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  11.5 KB  |  565 lines

  1. unit ntc_ciel_client_search;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     ExtCtrls,
  36.     StdCtrls,
  37.     Buttons,
  38.     inifiles,
  39.  
  40.     ntc_ciel_client_object,
  41.     ntc_ciel_client_form;
  42.  
  43. const
  44.     seconds_in=60*60;
  45.     seconds_in_az=360*seconds_in;
  46.     seconds_in_alt=360*seconds_in;
  47.     degrees_in_quarter=90;
  48.     percent_100=65535;
  49.     { correcting }
  50.     default_intercept=99.834586;
  51.     default_co_efficient_1=0.043221;
  52.     default_co_efficient_2=-0.017952;
  53.     default_co_efficient_3=5.71035432E-05;
  54.     default_height=240;
  55.     default_width=320;
  56.     default_height_part=20;
  57.     default_width_part=20;
  58.     default_seconds=1;
  59.     default_timeout=2000;
  60.  
  61. type
  62.     button_type_set=(
  63.         b_west,
  64.         b_east,
  65.         b_north,
  66.         b_south);
  67.     button_type=set of button_type_set;
  68.  
  69.     Tscope_search = class(TForm)
  70.         search_panel: TPanel;
  71.         dimensions_group: TGroupBox;
  72.         cycler_group: TGroupBox;
  73.         timeout_edit: TEdit;
  74.         timeout_label: TLabel;
  75.         out_panel: TPanel;
  76.         search_timer: TTimer;
  77.         out_label: TLabel;
  78.         in_panel: TPanel;
  79.         in_label: TLabel;
  80.         clock_panel: TPanel;
  81.         clock_label: TLabel;
  82.         counter_panel: TPanel;
  83.         counter_label: TLabel;
  84.         out_button: TSpeedButton;
  85.         in_button: TSpeedButton;
  86.         clock_button: TSpeedButton;
  87.         counter_button: TSpeedButton;
  88.     reset_group: TGroupBox;
  89.     stop_panel: TPanel;
  90.     stop_button: TSpeedButton;
  91.     stop_label: TLabel;
  92.     reset_panel: TPanel;
  93.     reset_label: TLabel;
  94.     reset_button: TSpeedButton;
  95.         { end test code *** }
  96.  
  97.         { form handlling }
  98.         procedure FormCreate(
  99.             Sender: TObject);
  100.  
  101.         procedure form_close_query(
  102.                     Sender: TObject;
  103.             var CanClose: Boolean);
  104.  
  105.         procedure disable_panel;
  106.         procedure enable_panel;
  107.  
  108.         { configuration }
  109.         procedure save_settings;
  110.  
  111.         procedure load_settings;
  112.  
  113.         procedure flip_buttons(
  114.             toggle:boolean);
  115.  
  116.         { slewing functions }
  117.         procedure reset;
  118.  
  119.         procedure move_screen(
  120.             t:string);
  121.  
  122.         { events }
  123.         procedure out_buttonClick(
  124.             Sender: TObject);
  125.  
  126.         procedure change_button(
  127.             button:string);
  128.  
  129.         procedure clock_buttonClick(
  130.             Sender: TObject);
  131.  
  132.         procedure counter_buttonClick(
  133.             Sender: TObject);
  134.  
  135.         procedure in_buttonClick(
  136.             Sender: TObject);
  137.  
  138.         procedure reset_buttonClick(
  139.             Sender: TObject);
  140.  
  141.         procedure stop_buttonClick(
  142.             Sender: TObject);
  143.  
  144.         procedure FormShow(
  145.             Sender:TObject);
  146.  
  147.         procedure adjust;
  148.  
  149.         procedure check_activate(
  150.             Sender: TObject);
  151.  
  152.         { timer }
  153.         procedure enable_timer;
  154.         procedure disable_timer;
  155.         procedure poll_scope;
  156.  
  157.         procedure search_timerTimer(
  158.             Sender: TObject);
  159.  
  160.         procedure timeout_editClick(
  161.             Sender: TObject);
  162.  
  163.     private
  164.         { Private declarations }
  165.         timeout_interval:integer;
  166.         dont_reset:boolean;
  167.     public
  168.         { Public declarations }
  169.         { moving }
  170.         frame_level:integer;
  171.         frame_dir:string;
  172.         { configuration }
  173.         dimensions:dimensions_record;
  174.  
  175.         { events }
  176.         procedure check_visible_and_show_hide(
  177.             sender:tobject);
  178.  
  179.         procedure hide_form;
  180.         procedure show_form;
  181.     end;
  182.  
  183. var
  184.     scope_search: Tscope_search;
  185.  
  186. implementation
  187.  
  188. uses
  189.     ntc_ciel_client_network,
  190.     ntc_ciel_client_info,
  191.     ntc_ciel_client_control;
  192.  
  193. {$R *.dfm}
  194. {$R icons.res}
  195.  
  196.     { -------------
  197.         form handling
  198.         ------------- }
  199.  
  200. procedure Tscope_search.FormCreate(
  201.     Sender: TObject);
  202. begin
  203.     search_timer.enabled:=false;
  204.     flip_buttons(false);
  205.     load_settings;
  206.     dont_reset:=false;
  207.     visible:=false;
  208. end;
  209.  
  210. procedure tscope_search.form_close_query(
  211.             Sender: TObject;
  212.     var CanClose: Boolean);
  213. begin
  214.     visible:=false;
  215.     with dimensions do
  216.         begin
  217.             form_top:=top;
  218.             form_left:=left;
  219.         end;
  220.     if ciel_closing then
  221.         canclose:=true
  222.     else
  223.         canclose:=false;
  224. end;
  225.  
  226. procedure tscope_search.disable_panel;
  227. begin
  228.     flip_buttons(false);
  229.     out_button.enabled:=false;
  230.     in_button.enabled:=false;
  231.     clock_button.enabled:=false;
  232.     counter_button.enabled:=false;
  233. end;
  234.  
  235. procedure tscope_search.enable_panel;
  236. begin
  237.     flip_buttons(true);
  238.     out_button.enabled:=true;
  239.     in_button.enabled:=true;
  240.     clock_button.enabled:=true;
  241.     counter_button.enabled:=true;
  242. end;
  243.  
  244. procedure tscope_search.FormShow(
  245.     Sender:TObject);
  246. begin
  247.     with dimensions do
  248.         begin
  249.             top:=form_top;
  250.             left:=form_left;
  251.         end;
  252. end;
  253.  
  254. procedure tscope_search.adjust;
  255. begin
  256.     with dimensions do
  257.         begin
  258.             form_top:=trunc(form_top/last_screen_height*current_height);
  259.             form_left:=trunc(form_left/last_screen_width*current_width);
  260.         end;
  261.     if visible then
  262.         show;
  263. end;
  264.  
  265. procedure tscope_search.check_visible_and_show_hide(
  266.     sender:tobject);
  267. begin
  268.     if visible then
  269.         hide_form
  270.     else
  271.         show_form;
  272.     scope.show_hide(sender,visible);
  273. end;
  274.  
  275. procedure tscope_search.hide_form;
  276. begin
  277.     with dimensions do
  278.         begin
  279.             form_top:=top;
  280.             form_left:=left;
  281.         end;
  282.     Visible:=false;
  283.     formstyle:=fsnormal;
  284. end;
  285.  
  286. procedure tscope_search.show_form;
  287. begin
  288.     formstyle:=fsstayontop;
  289.     Visible:=true;
  290. end;
  291.  
  292. procedure tscope_search.check_activate(
  293.     Sender: TObject);
  294. begin
  295.     scope.form_activate(scope_search,@dimensions);
  296. end;
  297.  
  298.     { ---------
  299.         utilities
  300.         --------- }
  301.  
  302. procedure tscope_search.flip_buttons(
  303.     toggle:boolean);
  304. begin
  305.     dimensions_group.enabled:=toggle;
  306.     cycler_group.enabled:=toggle;
  307.     reset_group.Enabled:=toggle;
  308. end;
  309.  
  310.     { -------------
  311.         configuration
  312.         ------------- }
  313.  
  314. procedure tscope_search.load_settings;
  315. begin
  316.     ini_file:=tinifile.create(application_path+'ciel.ini');
  317.     with ini_file do
  318.         begin
  319.             dont_reset:=true;
  320.             timeout_interval:=readinteger('search','timeout_interval',default_timeout);
  321.             timeout_edit.text:=inttostr(timeout_interval);
  322.             { form }
  323.             scope.get_dimensions(scope_search,@dimensions,'search',ini_file);
  324.             left:=dimensions.form_left;
  325.             top:=dimensions.form_top;
  326.             visible:=readbool('search','visible',false);
  327.             dont_reset:=false;
  328.         end;
  329.     ini_file.free;
  330. end;
  331.  
  332. procedure tscope_search.save_settings;
  333. begin
  334.     with ini_file do
  335.         begin
  336.             writeinteger('search','interval_timeout',timeout_interval);
  337.             { form }
  338.             scope.find_vdu(scope_search,@dimensions);
  339.             scope.write_dimensions(@dimensions,left,top,'search',ini_file);
  340.             writebool('search','visible',visible);
  341.         end;
  342. end;
  343.  
  344.     { -----------------
  345.         slewing functions
  346.         ----------------- }
  347.  
  348. procedure tscope_search.reset;
  349. begin
  350.     if scope_control.moving_scope then
  351.         disable_timer;
  352.     if scope_network.send_request_check('reset_search')>=[exit_ok] then
  353.         frame_level:=0;
  354.     enable_panel;
  355. end;
  356.  
  357.     { ----------------------------
  358.         move out to larger perimeter
  359.         ---------------------------- }
  360.  
  361. procedure Tscope_search.move_screen(
  362.     t:string);
  363. begin
  364.     if scope_network.send_request_check('move_screen_'+t)>=[exit_ok] then
  365.         enable_timer;
  366. end;
  367.  
  368. procedure Tscope_search.out_buttonClick(
  369.     Sender: TObject);
  370. var
  371.     b:string;
  372. begin
  373.     disable_panel;
  374.     with scope_network do
  375.          if not (send_request_check('break_out')=[exit_ok]) then
  376.         scope_control.write_status_log('invalid response from server')
  377.     else
  378.         begin
  379.             if scope_network.get_string('button',b) then
  380.                 change_button(b);
  381.             inc(frame_level);
  382.             enable_timer;
  383.         end;
  384. end;
  385.  
  386.     { -------------------
  387.         move to inner frame
  388.         ------------------- }
  389.  
  390. procedure Tscope_search.in_buttonClick(
  391.     Sender: TObject);
  392. begin
  393.     if frame_level>0 then
  394.          with scope_network do
  395.         begin
  396.             disable_panel;
  397.             if not (send_request_check('fall_in')=[exit_ok]) then
  398.                 scope_control.write_status_log('invalid response from server')
  399.             else
  400.                 begin
  401.                     dec(frame_level);
  402.                     enable_timer;
  403.                 end;
  404.         end;
  405. end;
  406.  
  407.     { ------------------
  408.         move to next frame
  409.         ------------------ }
  410.  
  411. procedure tscope_search.change_button(
  412.     button:string);
  413. begin
  414.     if button='north' then
  415.         begin
  416.             clock_button.glyph.LoadFromResourceName(hInstance,'NORTH_CLOCK');
  417.             counter_button.glyph.LoadFromResourceName(hInstance,'NORTH_ANTI');
  418.         end
  419.     else if button='south' then
  420.         begin
  421.             clock_button.glyph.LoadFromResourceName(hInstance,'SOUTH_CLOCK');
  422.             counter_button.glyph.LoadFromResourceName(hInstance,'SOUTH_ANTI');
  423.         end
  424.     else if button='east' then
  425.         begin
  426.             clock_button.glyph.LoadFromResourceName(hInstance,'EAST_CLOCK');
  427.             counter_button.glyph.LoadFromResourceName(hInstance,'EAST_ANTI');
  428.         end
  429.     else if button='west' then
  430.         begin
  431.             clock_button.glyph.LoadFromResourceName(hInstance,'WEST_CLOCK');
  432.             counter_button.glyph.LoadFromResourceName(hInstance,'WEST_ANTI');
  433.         end;
  434. end;
  435.  
  436. procedure Tscope_search.clock_buttonClick(
  437.     Sender: TObject);
  438. var
  439.     b:string;
  440. begin
  441.     disable_panel;
  442.     if scope_network.send_request_check('clockwise')>=[exit_ok] then
  443.         begin
  444.             enable_timer;
  445.             if scope_network.get_string('button',b) then
  446.                 change_button(b);
  447.         end
  448.     else
  449.         scope_control.write_status_log('invalid direction');
  450. end;
  451.  
  452. procedure Tscope_search.counter_buttonClick(Sender: TObject);
  453. var
  454.     b:string;
  455. begin
  456.     disable_panel;
  457.     if scope_network.send_request_check('counter')>=[exit_ok] then
  458.         begin
  459.             enable_timer;
  460.             if scope_network.get_string('button',b) then
  461.                 change_button(b);
  462.         end
  463.     else
  464.         scope_control.write_status_log('invalid direction');
  465. end;
  466.  
  467.     { -----------
  468.         reset event
  469.         ----------- }
  470.  
  471. procedure Tscope_search.reset_buttonClick(
  472.     Sender: TObject);
  473. begin
  474.     if not dont_reset then
  475.         reset;
  476. end;
  477.  
  478.     { ----------
  479.         stop event
  480.         ---------- }
  481.  
  482. procedure Tscope_search.stop_buttonClick(
  483.     Sender: TObject);
  484. begin
  485.     if not dont_reset then
  486.         reset;
  487.     scope_control.stop_scope;
  488. end;
  489.  
  490.     { -----
  491.         timer
  492.         ----- }
  493.  
  494. procedure tscope_search.enable_timer;
  495. begin
  496.     scope_control.change_panel(false);
  497.     search_timer.Interval:=timeout_interval;
  498.     search_timer.enabled:=true;
  499. end;
  500.  
  501. procedure tscope_search.disable_timer;
  502. begin
  503.     search_timer.enabled:=false;
  504.     scope_info.show_info;
  505.     scope_control.moving_scope:=false;
  506.     scope_control.change_panel(true);
  507. end;
  508.  
  509. procedure tscope_search.poll_scope;
  510. var
  511.     moving:boolean;
  512. begin
  513.     with scope_network do
  514.          if send_request_check('stopped')>=[exit_ok] then
  515.         begin
  516.             get_boolean('moving',moving);
  517.             if not moving then
  518.                 begin
  519.                     scope_control.moving_scope:=false;
  520.                     disable_timer;
  521.                 end;
  522.         end;
  523. end;
  524.  
  525. procedure Tscope_search.search_timerTimer(
  526.     Sender: TObject);
  527. begin
  528.     if not scope_network.network_timer.enabled then
  529.         poll_scope;
  530. end;
  531.  
  532. procedure overlap_change(
  533.     var s:string;
  534.     var def:double);
  535. var
  536.     d:double;
  537. begin
  538.     while (length(s)>0) and
  539.                 ((copy(s,length(s),1)>'9') or
  540.                 (copy(s,length(s),1)<'0')) do
  541.         s:=copy(s,1,length(s)-1);
  542.     if length(s)=0 then
  543.         d:=20
  544.     else
  545.         d:=strtofloatdef(s,def);
  546.     if (d>=0) and (d<100) then
  547.         def:=d
  548.     else
  549.         s:=floattostr(def);
  550.     s:=s+'%';
  551. end;
  552.  
  553. procedure Tscope_search.timeout_editClick(
  554.     Sender: TObject);
  555. begin
  556.     timeout_interval:=strtointdef(timeout_edit.text,2000);
  557.     if timeout_interval<2000 then
  558.         begin
  559.             timeout_interval:=2000;
  560.             timeout_edit.text:=inttostr(timeout_interval);
  561.         end;
  562. end;
  563.  
  564. end.
  565.